<template>
    <div>
        {{ info }}
        <table>
            <thead>
                <tr>
                    <td>用户名</td>
                    <td><input type="text" v-model="info.name" ></td>
                </tr>
                <tr>
                    <td>密码</td>
                    <td><input type="password" v-model="info.pwd" ></td>
                </tr>

                <tr>
                    <td></td>
                    <td><input type="button" value="登录" @click="Login" ></td>
                </tr>
            </thead>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref } from 'vue';
import { useRouter } from 'vue-router';

const router=useRouter();

let info:any=ref({
    name:'',
    pwd:''
});

const Upda=()=>{
    router.push({
        path:'/Add',
    })
}

const Login=()=>{
    if(info.value.name=="" )
{
    alert("用户名不为空");
    return;
}
    if(info.value.pwd=="" )
{
    alert("密码不为空");
    return;
}
    axios({
        url:'https://localhost:7073/api/User/Login',
        method:'post',
        params:info.value
    })
    .then((res)=>{
        console.log(res);
        if(res.data==-1 )
    {
        alert("用户名不正确");
        return;
    }
       if(res.data==-2 )
    {
        alert("密码不正确");
        return;
    }  
       if(res.data==-3 )
    {
        alert("账号被冻结");
        return;
    }
       if(res.data>0 )
    {
        alert("成功");
        Upda();
    }

    } )
}

</script>

<style scoped>

</style>